package com.education.wisdom.controller.app;

import com.education.common.utils.IpUtils;
import com.education.common.utils.LogUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

import static com.education.common.core.BaseController.writeJSON;


@Controller
@RequestMapping("applog")
@Slf4j
public class AppLogController {



    /**
     * 接收iOS端发过来的日志
     */
    @RequestMapping("/createIos")
    @ResponseBody
    public void setIapCertificate(HttpServletRequest request,HttpServletResponse response, String logs, String type) throws IOException {
      //  log.info(LogUtil.LogInfo(type+":"+logs, new Date()));
        String ip=IpUtils.getIpAddr(request);
        log.error(LogUtil.LogInfo(type+":"+"IP:"+ip+logs, new Date()));
        writeJSON(null, response, "200", "成功");

    }

    /**
     * 接收HTML端发过来的日志
     */
    @RequestMapping("/createHtml")
    @ResponseBody
    public void createHtml(HttpServletRequest request,HttpServletResponse response, String logs, String type) throws IOException {
        String ip= IpUtils.getIpAddr(request);
        log.error(LogUtil.LogInfo(type+":"+"IP:"+ip+logs, new Date()));
        writeJSON(null, response, "200", "成功");

    }

    /**
     * 接收安卓端发过来的日志
     */
    @RequestMapping("/createAndroid")
    @ResponseBody
    public void createAndroid(HttpServletRequest request,HttpServletResponse response, String logs, String type) throws IOException {
        String ip=IpUtils.getIpAddr(request);
        log.error(LogUtil.LogInfo(type+":"+"IP:"+ip+logs, new Date()));
        writeJSON(null, response, "200", "成功");

    }

}
